package ca.uvic.cs.cogz.mapping;

import java.util.ArrayList;

import ca.uvic.cs.cogz.mapping.core.AbstractMapElement;
import edu.stanford.smi.protegex.prompt.actionLists.SuggestionsAndConflicts;
import edu.stanford.smi.protegex.prompt.operation.Operation;
import edu.stanford.smi.protegex.prompt.plugin.util.KnowledgeBaseFacade;

public class SuggestionsManager {
	/** all suggestions calculated during PROMPT's algorithm process */
	@SuppressWarnings("unchecked")
	private ArrayList allSuggestions;

	public SuggestionsManager() {
		allSuggestions = getAllSuggestions();
	}

	/**
	 * Refresh the working suggestions if our visible suggestions are out of sync with Prompt's
	 * 
	 * @return True if the working suggestions were refreshed
	 */
	@SuppressWarnings("unchecked")
	public boolean refreshWorkingSuggestions() {
		return !((ArrayList) KnowledgeBaseFacade.getToDoListInPriorityOrder()).equals(allSuggestions);
	}

	public void updateWorkingSuggestions() {
		allSuggestions = getAllSuggestions();
	}

	@SuppressWarnings("unchecked")
	public ArrayList getWorkingSuggestions() {
		return allSuggestions;
	}

	@SuppressWarnings("unchecked")
	public ArrayList getAllSuggestions() {
		return (ArrayList) KnowledgeBaseFacade.getToDoListInPriorityOrder();
	}

	public Operation getOperationForMapping(AbstractMapElement mapElement) {
		return mapElement.getOperation();
	}

	public void removeCandidateMapping(AbstractMapElement mapElement) {
		Operation operation = getOperationForMapping(mapElement);
		SuggestionsAndConflicts.removeSuggestionFromList(operation);
	}
}
